/*
 * Copyright (c) 2006, 2023, webrx.cn All rights reserved.
 *
 */
package cn.webrx;

import java.text.SimpleDateFormat;

/**
 * <p>Project: jse2302 - Ex10
 * <p>Powered by webrx On 2023-06-13 14:56:11
 * <p>Created by IntelliJ IDEA
 *
 * @author  webrx [webrx@126.com]
 * @version 1.0
 * @since 17
 */
public class Ex10 {
    public static void main(String[] args) throws Exception {
        var sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        var time = sdf.parse("2023-06-1 08:30:30").getTime();
        System.out.printf("%tF %<tT%n", time);
        String msg = "你好，在吗？";
        System.out.println(121);
        var now = System.currentTimeMillis();
        if (now - time < 60000) {//刚刚
            System.out.printf("刚刚：%s%n", msg);
        } else if (now - time < 1000 * 60 * 60) { //分钟前
            long m = (now - time) / (1000 * 60);
            System.out.printf("%d分钟前：%s%n", m, msg);
        } else if (now - time < 1000 * 60 * 60 * 24) {//小时前
            long m = (now - time) / (1000 * 60 * 60);
            System.out.printf("%d小时前：%s%n", m, msg);
        } else if (now - time < 1000 * 60 * 60 * 24 * 7L) {//天前
            long m = (now - time) / (1000 * 60 * 60 * 24);
            System.out.printf("%d天前：%s%n", m, msg);
        } else {//如果超过7天前，就原时间显示
            System.out.printf("%tF %<tT：%s%n", time, msg);
        }
    }
}
